package com.example.ktsb.service.impl

import com.example.ktsb.entity.User
import com.example.ktsb.repository.UserRepository
import com.example.ktsb.service.UserService
import org.springframework.data.domain.Example
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service

@Service
class UserServiceImpl(private val userRepository: UserRepository) : UserService {

    override fun addUser(user: User): User {
        return userRepository.save(user)
    }

    override fun updateUser(user: User): User {
        return userRepository.save(user)
    }

    override fun deleteUser(userId: Long) {
        userRepository.deleteById(userId)
    }

    override fun getUserByName(user: User): List<User> {
        return userRepository.getUser(user.userName)
    }

    override fun findUserList(user: User): List<User> {
        return userRepository.findAll(Example.of(user))
    }

    override fun findUserListByStatus(status: Int, pageable: Pageable): Page<User> {
        return userRepository.findByStatus(status, pageable)
    }

}